<template>
  <div class="bill-box" v-loading="loading">
    <el-form ref="fmData" :model="fmData" :rules="rules" v-if="fmData != null">
      <div class="purchas-information">
        <el-card class="box-card">
          <div slot="header" class="unfold-way">
            <p>采购订单</p>
            <div class="button-plan">
              <span
                v-if="
                  fmStatus == 'seeStatus' && $route.query.open !== 'addStatus'
                "
              >
                <el-button
                  @click="btnAdd('view')"
                  type="primary"
                  v-hasPermi="['po:order:entity:add']"
                  :disabled="option.stripStatus"
                >
                  新增</el-button
                >
              </span>
              <span
                v-if="
                  fmStatus == 'seeStatus' && $route.query.open == 'addStatus'
                "
              >
                <el-button
                  @click="btnAdd('add')"
                  type="primary"
                  v-hasPermi="['po:order:entity:add']"
                  :disabled="option.stripStatus"
                  v-if="fmStatus == 'seeStatus'"
                >
                  新增</el-button
                >
              </span>
              <span v-if="fmStatus == 'updateStatus'">
                <el-button
                  type="primary"
                  @click="btnSave(fmData)"
                  :disabled="option.btnIsClick || fmStatus !== 'updateStatus'"
                  v-hasPermi="['po:order:entity:edit']"
                  >保存
                </el-button>
                <el-button type="succes" @click="btnUndo">撤回</el-button>
              </span>
              <span v-if="fmStatus == 'addStatus'">
                <el-button
                  type="primary"
                  v-hasPermi="['po:order:entity:add']"
                  @click="btnNew(fmData)"
                  :disabled="option.btnIsClick"
                  >保存</el-button
                >
              </span>
              <span>
                <el-button
                  type="succes"
                  v-if="fmStatus == 'seeStatus'"
                  v-hasPermi="['po:order:entity:edit']"
                  @click="btnEdit"
                  :disabled="
                    fmData.invoiceStatus == '1' || fmStatus !== 'seeStatus'
                  "
                  >编辑</el-button
                >
                <el-button
                  type="succes"
                  v-if="fmStatus == 'addStatus'"
                  @click="btnCancel"
                  >取消</el-button
                >
                <el-button
                  type="success"
                  v-hasPermi="['po:order:permit']"
                  @click="btnCheck"
                  :disabled="
                    fmStatus !== 'seeStatus' ||
                    fmData.invoiceStatus == '1' ||
                    fmData.invoiceStatus == '2'
                  "
                >
                  审核</el-button
                >
                <el-button
                  type="info"
                  v-hasPermi="['po:order:revoke']"
                  @click="btnUnCheck"
                  :disabled="
                    fmStatus !== 'seeStatus' ||
                    fmData.invoiceStatus == '0' ||
                    fmData.invoiceStatus == '2'
                  "
                  >反审核
                </el-button>
              </span>
              <span>
                <el-button
                  type="success"
                  plain
                  icon="el-icon-printer"
                  size="mini"
                  @click="objPrinter.handlePrint()"
                  v-hasPermi="['po:order:print']"
                  v-if="fmStatus == 'seeStatus'"
                  >打印</el-button
                >
                <el-dropdown
                  @command="btnOperation"
                  trigger="click"
                  v-hasPermi="['po:order:operate']"
                  v-if="fmStatus == 'seeStatus' || fmStatus == 'updateStatus'"
                >
                  <el-button type="primary" plain>
                    操作<i class="el-icon-arrow-down el-icon--right"></i>
                  </el-button>
                  <el-dropdown-menu slot="dropdown" class="menu-drop-box">
                    <el-dropdown-item
                      :command="'1'"
                      :class="{ active: stack.commandIndex == '1' }"
                    >
                      <i
                        class="el-icon-check"
                        v-if="stack.commandIndex == '1'"
                      ></i
                      ><span>挂起</span>
                    </el-dropdown-item>
                    <el-dropdown-item
                      :command="'2'"
                      :class="{ active: stack.commandIndex == '2' }"
                    >
                      <i
                        class="el-icon-check"
                        v-if="stack.commandIndex == '2'"
                      ></i
                      ><span>关闭</span>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </span>
              <span>
                <el-button
                  type="text"
                  @click="objHelper.downToggle()"
                  style="padding: 0"
                  >{{ style.downTitle }}</el-button
                >
              </span>
            </div>
          </div>
          <collapseTransition>
            <div class="info-list" v-show="style.isToggle" ref="toggleBox">
              <div class="wn-in-box">
                <div class="list-box">
                  <div class="box-input">
                    <p>单据编码：</p>
                    <el-form-item>
                      <el-input type="input" v-model="fmData.poCode" disabled>
                      </el-input>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>单据日期：</p>
                    <el-form-item prop="invoiceDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        :disabled="option.disabledInput"
                        placeholder="选择日期"
                        v-model="fmData.invoiceDate"
                        style="width: 100%"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </div>
                  <div class="box-input blue-color">
                    <p>单据状态：</p>
                    <div class="invoice-box">
                      <span
                        v-if="fmData.invoiceStatus == '0'"
                        style="color: #e6a23c"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                      <span
                        v-if="fmData.invoiceStatus == '1'"
                        style="color: #67c23a"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                      <span
                        v-if="fmData.invoiceStatus == '2'"
                        style="color: #909399"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                    </div>
                  </div>
                  <div class="box-input">
                    <p>单据类型：</p>
                    <el-form-item>
                      <el-select
                        v-model="fmData.invoiceType"
                        placeholder="请选择"
                        disabled
                      >
                        <el-option
                          v-for="item in enums.optionsInvoiceType"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                </div>
                <div class="list-box">
                  <div class="box-input">
                    <p>业务类型：</p>
                    <el-form-item>
                      <el-select
                        v-model="fmData.workType"
                        :disabled="option.wmworkStatus || entryMode"
                        placeholder="请选择"
                        @change="objHelper.workTypeChange($event)"
                      >
                        <el-option
                          v-for="item in enums.optionsworkType"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                  <div class="box-input blue-color">
                    <p>业务状态：</p>
                    <el-form-item prop="workStatus">
                      <el-select
                        v-model="fmData.workStatus"
                        :disabled="option.disabledInput"
                      >
                        <el-option
                          v-for="item in enums.optionsworkStatus"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>采购部门：</p>
                    <el-form-item prop="workDept">
                      <el-cascader
                        v-model="enums.selectworkDept"
                        :options="enums.optionsworkDept"
                        :disabled="option.disabledInput"
                        :props="style.classProps"
                        @change="objHelper.workDeptChange($event)"
                        ref="classTree"
                        class="cas-input"
                      ></el-cascader>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>采购人员：</p>
                    <el-form-item prop="workStaff">
                      <el-select
                        v-model="stack.selectworkStaff"
                        :disabled="
                          option.disabledInput || fmData.workDept == ''
                        "
                        @change="objHelper.workStaffChange($event)"
                      >
                        <el-option
                          v-for="(item, id) in stack.optionsworkStaff"
                          :key="id"
                          :label="item.nickName"
                          :value="item.nickName"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                </div>
                <div class="list-box">
                  <div class="box-input">
                    <p>操作员：</p>
                    <el-form-item>
                      <el-input v-model="fmData.userOper" disabled> </el-input>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>审核员：</p>
                    <el-form-item>
                      <el-input v-model="fmData.userCheck" disabled> </el-input>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>审核日期：</p>
                    <el-form-item prop="checkDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        v-model="fmData.checkDate"
                        style="width: 100%"
                        disabled
                      ></el-date-picker>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>用料需求：</p>
                    <el-form-item prop="saleType">
                      <el-select
                        v-model="fmData.needType"
                        :disabled="fmStatus !== 'addStatus'"
                        placeholder="请选择"
                        @change="objHelper.needTypeChange($event)"
                      >
                        <el-option
                          v-for="item in enums.optionsNeedType"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                </div>
                <div class="list-box">
                  <div class="box-input" v-hasPermi="['po:order:supplier']">
                    <p style="width: 70px !important">供方：</p>
                    <el-form-item prop="supplier">
                      <div
                        class="box-add"
                        :style="{
                          background:
                            fmStatus == 'seeStatus' ? '#f5f7fa' : '#fff',
                        }"
                      >
                        <el-input
                          type="input"
                          :class="{ 'om-see': fmStatus == 'seeStatus' }"
                          @input="
                            objSupplier.searchPoPuPrs(
                              fmData.supplier,
                              'poSearch'
                            )
                          "
                          v-model="fmData.supplier"
                          @keypress.native.enter="
                            objSupplier.nameEnter(fmData.supplier, 'poSearch')
                          "
                          :disabled="option.disabledInput"
                        >
                        </el-input>
                        <el-link
                          class="input-select"
                          type="primary"
                          v-if="!stack.poStatus && fmStatus !== 'seeStatus'"
                          @click="objSupplier.handlePoPuPrs('po')"
                          >选择
                        </el-link>
                      </div>
                    </el-form-item>

                    <div class="select-popu" v-if="stack.poSearchStatus">
                      <div class="drop-menu">
                        <div class="ma-list">
                          <div class="menu-close">
                            <div class="search-top">
                              <span>搜索结果</span>
                              <a
                                class="el-icon-close"
                                @click="
                                  objSupplier.handleClosePoPuPrs('poSearch')
                                "
                              ></a>
                            </div>
                          </div>
                          <p v-if="stack.optionssupplier.length == 0">无数据</p>
                          <div
                            class="list-t"
                            v-for="(item, index) in stack.optionssupplier"
                            @click="
                              objSupplier.successPoPuPrs(item, 'poSearch')
                            "
                            :key="index"
                          >
                            <div class="po-content">
                              <span>{{ item.name }}</span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="box-input">
                    <p>到货日期：</p>
                    <el-form-item prop="arrivalDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        :disabled="option.disabledInput"
                        placeholder="选择日期"
                        v-model="fmData.arrivalDate"
                        style="width: 100%"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </div>

                  <div class="sc-upload">
                    <p>采购合同：</p>
                    <div
                      class="box-upload"
                      :class="{ 'bac-uplode': fmStatus == 'seeStatus' }"
                    >
                      <div
                        class="upload-con"
                        v-for="(uploadItem, index) in stack.uploadList"
                        :key="index"
                        @mouseenter="objUpload.mouseenter(uploadItem)"
                        @mouseleave="objUpload.mouseleave(uploadItem)"
                      >
                        <span
                          ><i class="el-icon-document"></i
                          >{{ uploadItem.fileName }}</span
                        >
                        <label>
                          <i
                            class="el-icon-download"
                            style="color: #1890ff"
                            v-show="
                              (uploadItem.opShow && fmStatus == 'seeStatus') ||
                              (uploadItem.opShow && fmStatus == 'updateStatus')
                            "
                            @click="
                              objUpload.handleDownload(
                                uploadItem.fileName,
                                uploadItem.path
                              )
                            "
                          ></i>
                          <i
                            v-show="
                              (uploadItem.opShow &&
                                fmStatus == 'seeStatus' &&
                                uploadItem.pdfStatus == true) ||
                              (uploadItem.opShow &&
                                fmStatus == 'updateStatus' &&
                                uploadItem.pdfStatus == true)
                            "
                            class="el-icon-view"
                            style="color: #42d885"
                            @click="
                              objUpload.handlePreview(
                                uploadItem.fileName,
                                uploadItem.path
                              )
                            "
                          ></i>
                          <i
                            v-show="
                              (uploadItem.opShow && fmStatus == 'addStatus') ||
                              (uploadItem.opShow && fmStatus == 'updateStatus')
                            "
                            class="el-icon-delete"
                            style="color: #ff4949"
                            @click="objUpload.handleDeleteImport(index)"
                          ></i
                        ></label>
                      </div>
                      <el-link
                        v-if="
                          fmStatus == 'addStatus' || fmStatus == 'updateStatus'
                        "
                        style="
                          font-size: 13px;
                          margin-left: 5px;
                          margin-top: 7px;
                        "
                        type="primary"
                        v-hasPermi="['po:order:upload']"
                        @click="objUpload.handleUpload"
                        >上传
                      </el-link>
                    </div>
                  </div>
                  <div class="box-input">
                    <p>备注信息：</p>
                    <el-form-item prop="remarks">
                      <el-input
                        type="textarea"
                        autosize
                        v-model="fmData.remarks"
                        :disabled="option.disabledInput"
                      >
                      </el-input>
                    </el-form-item>
                  </div>
                </div>
              </div>
              <div class="articles-numbers" v-if="fmStatus == 'seeStatus'">
                <el-link
                  type="success"
                  v-hasPermi="['po:order:next']"
                  @click="btnForward(fmData.poCode, 'last')"
                  :disabled="option.stripStatus"
                  >上一条
                </el-link>
                <el-link
                  type="success"
                  v-hasPermi="['po:order:next']"
                  @click="btnForward(fmData.poCode, 'next')"
                  :disabled="option.stripStatus"
                  >下一条
                </el-link>
              </div>
            </div>
          </collapseTransition>
        </el-card>
      </div>
      <div class="purchas-content" v-show="option.parametersStatus == true">
        <el-card class="box-card">
          <div slot="header" class="unfold-way">
            <p>物料信息</p>
            <div v-if="fmStatus == 'addStatus' || fmStatus == 'updateStatus'">
              <el-button
                v-hasPermi="['po:order:import']"
                type="warning"
                plain
                icon="el-icon-download"
                @click="objMaterial.handleImportMaterialSelect()"
              >
                引入</el-button
              >
              <el-button
                v-if="fmData.needType !== '0'"
                v-hasPermi="['po:order:add']"
                type="primary"
                plain
                icon="el-icon-plus"
                @click="objMaterial.addMaterial()"
              >
                新增物料</el-button
              >
            </div>
          </div>
          <div class="info-table">
            <div class="table-data">
              <el-table
                :data="fmData.poOrderSalveList"
                border
                :height="style.tableHeight"
                ref="tableClums"
                style="width: 100%"
              >
                <template slot="empty">
                  <span></span>
                </template>
                <el-table-column type="index" width="40" label="序号" :key="1">
                </el-table-column>
                <el-table-column label="采购计划号" width="120">
                  <template slot-scope="scope">
                    <el-form-item class="sales-man">
                      <el-input v-model="scope.row.woCode" disabled> </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
            
                <el-table-column
                  label="销售订单号"
                  width="110"
                  v-if="fmData.needType == '0'"
                  :key="3"
                >
                  <template slot-scope="scope">
                    <el-form-item
                      :prop="'poOrderSalveList.' + scope.$index + '.ppNumber'"
                      :rules="rules.ppNumber"
                    >
                      <el-input
                        v-model="scope.row.ppNumber"
                        disabled
                        placeholder="销售订单号"
                      >
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="物料编码" :key="2" width="110">
                  <template slot-scope="scope">
                    <el-form-item
                      :prop="'poOrderSalveList.' + scope.$index + '.invCode'"
                      :rules="rules.invCode"
                    >
                      <div class="select-box">
                        <div class="select-name">
                          <el-input
                            v-model="scope.row.invCode"
                            @input="
                              objMaterial.searchCode(scope.$index, scope.row)
                            "
                            @keypress.native.enter="objMaterial.codeEnter()"
                            :disabled="
                              option.disabledInput || scope.row.woCode !== ''
                            "
                            placeholder="请添加物料"
                          >
                          </el-input>
                          <el-link
                            @click="objMaterial.btnItem(scope.$index)"
                            type="primary"
                            v-if="
                              (fmStatus == 'addStatus' &&
                                (scope.row.woCode == '' ||
                                  scope.row.woCode == null)) ||
                              (fmStatus == 'updateStatus' &&
                                (scope.row.woCode == '' ||
                                  scope.row.woCode == null))
                            "
                          >
                            选择</el-link
                          >
                        </div>
                        <div
                          class="drop-menu1"
                          ref="drop"
                          v-show="scope.$index == stack.saveIndex"
                          :name="scope.$index"
                        >
                          <div class="ma-list">
                            <div class="menu-close">
                              <div class="search-top">
                                <span>搜索结果</span>
                                <a
                                  class="el-icon-close"
                                  @click="objMaterial.handleHide()"
                                ></a>
                              </div>
                            </div>
                            <p v-if="stack.basicfileList.length == 0">无数据</p>
                            <div
                              class="list-t"
                              v-for="(item, index) in stack.basicfileList"
                              :key="index"
                              @click="objMaterial.successSelect(item)"
                              v-else
                            >
                              <div>
                                <span>{{ item.code }}</span>
                                <span
                                  >{{ item.name }}&nbsp;{{
                                    item.attribute
                                  }}</span
                                >
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="物料名称" width="250">
                  <template slot-scope="scope">
                    <div class="con-spec" v-if="fmConfig.attrMerge == 'true'">
                      <span
                        >{{ scope.row.invName
                        }}{{ scope.row.invAttribute }}</span
                      >
                    </div>
                    <el-form-item
                      :prop="'poOrderSalveList.' + scope.$index + '.invName'"
                      :rules="rules.invName"
                      v-if="fmConfig.attrMerge == 'false'"
                    >
                      <div class="select-name">
                        <el-input v-model="scope.row.invName" disabled>
                        </el-input>
                      </div>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column
                  :label="fmConfig.attrAlias"
                  width="100"
                  v-if="fmConfig.attrMerge == 'false'"
                >
                  <template slot-scope="scope">
                    <el-form-item
                      :prop="
                        'poOrderSalveList.' + scope.$index + '.invAttribute'
                      "
                      :rules="rules.invAttribute"
                    >
                      <el-input v-model="scope.row.invAttribute" disabled>
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="主计量" width="60">
                  <template slot-scope="scope">
                    <el-form-item
                      :prop="'poOrderSalveList.' + scope.$index + '.unitName'"
                      :rules="rules.unitName"
                    >
                      <el-input v-model="scope.row.unitName" disabled>
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="needDate" label="需求日期" width="120">
                  <template slot-scope="scope">
                    <el-date-picker
                      class="input-pp"
                      type="date"
                      :disabled="
                        option.disabledInput || scope.row.woUniqueId !== 0
                      "
                      placeholder="请选择"
                      v-model="scope.row.needDate"
                      style="width: 100%"
                    >
                    </el-date-picker>
                  </template>
                </el-table-column>

                <el-table-column prop="quantity" label="数量" width="100">
                  <template slot-scope="scope">
                    <el-form-item
                      class="text-right"
                      :prop="'poOrderSalveList.' + scope.$index + '.quantity'"
                      :rules="rules.quantity"
                      :class="{
                        'is-error':
                          parseFloat(scope.row.quantity) >
                            parseFloat(scope.row.woQuantity) &&
                          scope.row.woQuantity !== null &&
                          scope.row.woQuantity !== undefined,
                      }"
                    >
                      <el-input
                        v-model="scope.row.quantity"
                        :disabled="option.disabledInput"
                        @change="
                          objUtils.formatDecimal(scope.$index, scope.row)
                        "
                        style="text-align: right"
                      >
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column
                  label="单价"
                  width="100"
                  prop="price"
                  v-if="option.priceStatus"
                >
                  <template slot-scope="scope">
                    <el-form-item
                      class="text-right"
                      :prop="'poOrderSalveList.' + scope.$index + '.price'"
                      :rules="rules.price"
                    >
                      <el-input
                        v-model="scope.row.price"
                        :disabled="option.disabledInput"
                        @change="
                          objUtils.formatDecimal(scope.$index, scope.row)
                        "
                      >
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column
                  label="金额"
                  width="100"
                  v-if="option.priceStatus"
                >
                  <template slot-scope="scope">
                    <el-form-item class="text-right">
                      <span
                        v-if="scope.row.price == '' || scope.row.quantity == 0"
                        >0.00</span
                      >
                      <span v-else>{{
                        (scope.row.price * scope.row.quantity).toFixed(2)
                      }}</span>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="wiQuantity" label="到货数量" width="100">
                  <template slot-scope="scope">
                    <el-form-item class="text-right">
                      <el-input
                        v-model="scope.row.wiQuantity"
                        disabled
                        style="text-align: right"
                      >
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="remarks" label="采购说明">
                  <template slot-scope="scope">
                    <el-form-item>
                      <el-input
                        type="textarea"
                        autosize
                        v-model="scope.row.remarks"
                        :disabled="option.disabledInput"
                      >
                      </el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="50"
                  v-if="fmStatus == 'addStatus' || fmStatus == 'updateStatus'"
                  :key="16"
                >
                  <template slot-scope="scope">
                    <el-link
                      type="danger"
                      plain
                      @click="objMaterial.deleteList(scope.$index)"
                      >删除
                    </el-link>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-card>
      </div>
    </el-form>
    <!-- 上传采购合同附件 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
      @close="objUpload.closeUpload"
    >
      <el-upload
        ref="upload"
        multiple
        :on-exceed="objUpload.handleExceed"
        :limit="5"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :auto-upload="false"
        :on-change="objUpload.handleUploadChange"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许上传“docx”或“pdf”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="objUpload.submitFileForm"
          >确 定</el-button
        >
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 物料组件 -->
    <selectMaterial
      @handleSelect="objMaterial.handleSelect(arguments)"
      :sortArrId="fmConfig.sortArrId"
      :selectDialog="stack.selectDialog"
      v-show="stack.selectDialog"
      @selectClose="objMaterial.selectClose()"
    />

    <!-- 供方组件 -->
    <selectSupplier
      :selectSupplierDialog="stack.poStatus"
      @handleSupplierSelect="objSupplier.handleSupplierSelect($event)"
      v-if="stack.poStatus"
      @selectSupplierClose="objSupplier.selectSupplierClose()"
    />
    <!-- 选择引入物料组件 -->
    <selectImportMaterial
      :selectImportMaterialDialog="stack.ImportMaterialStatus"
      :needType="fmData.needType"
      @handleImportMaterialSelect="
        objMaterial.handleImportMaterialSelect($event)
      "
      :optionsworkType="enums.optionsworkType"
      :decimal="fmConfig.decimalQuantity"
      v-if="stack.ImportMaterialStatus"
      @selectImportMaterialClose="objMaterial.selectImportMaterialClose()"
      @handleImportMaterialSuccess="
        objMaterial.handleImportMaterialSuccess($event)
      "
    />
    <!-- 打印数据 -->
    <PrintPage
      :printData="print.printData"
      :priceStatus="option.priceStatus"
      :qrCodeValue="print.qrCodeValue"
      v-if="print.printStatus"
      ref="startPrint"
      :title="print.printTitle"
    />
    <div ref="file"></div>
  </div>
</template>

<script>
//接口
import {
  dictMatching, //系统字典
  listDept, //采购部门列表
  listUser, //采购人员(用户)
  addBill, //新增单据
  seeBill, //查看单据
  updateBill, //更新单据
  NextBill, //上一条下一条
  examineBill, //审核单据
  examineDeBill, //反审核单据
  listMaterial, //物料信息
  listSupplier, //获取供方
  moduleParameters,
  billParameters,
  uploadFiles,
  downLoad,
  operationBill, //操作
} from "../../api/order";
//js方法
import { getTreeData, getEcho } from "../../utils/purchase";
import { getToken } from "@/utils/auth";
//并行请求
import axios from "axios";
//输入是否为数字效验
import { isAccord } from "@/utils/cingsoft";
// 物料选择组件
import selectMaterial from "../../components/Common/selectMaterial.vue";
//供方选择组件
import selectSupplier from "../../components/Common/selectSupplier.vue";
//选择引入物料组件
import selectImportMaterial from "./selectImportMaterial.vue";
// //打印组件
import PrintPage from "../../components/Order/print";
export default {
  data() {
    // 单价输入效验
    var checkOutPrice = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };

    // 数量输入效验
    var checkOutQuantity = (rule, value, callback, param) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };
    return {
      // 遮罩层
      loading: false,

      //初始化状态
      initialStatus: false,

      // 进入表单模式，有参、无参
      entryMode: false,

      //进入表单参数
      entry: {
        //记录编辑查看物料编码
        seeCode: "",
        //记录当前路由信息用于关闭当前页面
        routeMsg: {},
        // 记录fmConfig,用于是否刷新当前页面,未做
        setConfig: "",
        //记录needType,用于是否刷新当前页面
        setNeedType: "",
          //记录时间戳,用于是否刷新当前页面
        timeStamp: "",
      },

      //表单状态-addStatus:新增状态,seeStatus:查看状态,updateStatus:编辑状态
      fmStatus: "",

      //数据表单
      fmData: {
        poAttachmentList: [],
      },

      //新增物料信息
      fmItem: {
        invSortId: "", //物料分类
        invCode: "", //物料编码
        invName: "", //物料名称
        invAttribute: "", //型号规格
        unitCode: "", //主计量
        unitName: "", //主计量
        quantity: "", //采购数量
        price: "", //采购单价
        amount: "0.00", //采购金额
        needDate: null,
        ppNumber: "",
        ppDate: null,
        salesman: "",
        woDate: null,
        woCode: "", //上游单据
        woUniqueId: 0, //上游物料
        woQantity: "",
        wiQantity: "",
        remarks: "", //备注
      },

      //单据参数信息
      fmConfig: {
        decimalQuantity: "2", //数量小数位数
        decimalPrice: "2", //数量小数位数
        attrMerge: "false", //规格合并
        attrAlias: "型号规格", //规格别名
        sortArrId: [], //料品大类
        fieldHiding: [], //隐藏字段
        property: [], //特殊属性
      },

      // 查询
      query: {
        code: "",
        sortRoot: "",
        type: true,
      },

      //选项
      option: {
        //按钮是否禁用
        btnIsClick: false,
        //输入框是否禁用
        disabledInput: false,
        //业务类型是否可更改
        wmworkStatus: false,
        //上一条下一条状态
        stripStatus: false,
        // 物料信息状态
        parametersStatus: false,
        //单价状态
        priceStatus: true,
      },

      //枚举
      enums: {
        //单据类型
        optionsInvoiceType: [],
        selectInvoiceType: "",
        //业务类型
        optionsworkType: [],
        selectworkType: "",
        //采购部门
        optionsworkDept: [],
        selectworkDept: [],
        //业务状态
        optionsworkStatus: [],
        selectworkStatus: "",
        //用料需求
        optionsNeedType: [],
        //用料方式
        optionsinvInType: [],
      },

      //执行中
      stack: {
        //操作下拉切换
        commandIndex: "",
        //点击选择物料记录下标，用于更新物料信息
        rowIndex: "",
        //物料选择弹框状态
        selectDialog: false,
        // 物料编码搜索下拉状态
        saveIndex: null,
        // 物料编码搜索数据
        basicfileList: [],
        //供方
        optionssupplier: [],
        poStatus: false,
        poSearchStatus: false,
        // 引入信息
        optionsImportMaterial: [],
        ImportMaterialStatus: false,
        //上传采购合同
        uploadList: [],
        //采购人员
        optionsworkStaff: [],
        selectworkStaff: "",
      },

      //样式
      style: {
        // 展开收起
        isToggle: true, //状态
        downTitle: "收起", //按钮辩题
        tableHeight: "", //物料信息高度
        // 标题
        pageTitle: "",
        //采购部门选择配置
        classProps: {
          children: "children",
          label: "deptName",
          value: "deptId",
        },
      },

      //打印
      print: {
        //打印组件状态
        printStatus: false,
        //打印数据
        printData: {},
        //打印名称
        printTitle: "",
        //二维码内容
        qrCodeValue: "",
        //打印部门
        printWorkDept: [],
      },

      // 采购合同上传参数
      upload: {
        // 是否显示弹出层（物料信息引入）
        open: false,
        // 弹出层标题（物料信息引入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        fileList: [], // upload多文件数组
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/po/order/upload",
      },

      //内存优化
      objMaterial: this.classMaterial(), //物料
      objSupplier: this.classSupplier(), //供方
      objUpload: this.classUpload(), //上传
      objPrinter: this.classPrinter(), //打印
      objHelper: this.classHelper(), //助手
      objUtils: this.classUtils(), //工具

      rules: {
        //是否必须输入
        invoiceDate: [
          {
            required: true,
            trigger: "change",
          },
        ],
        invCode: [
          {
            required: true,
            trigger: "change",
          },
        ],
        invName: [
          {
            required: true,
            trigger: "change",
          },
        ],
        quantity: [
          {
            validator: checkOutQuantity,
            required: true,
            trigger: "blur",
          },
        ],
        price: [
          {
            validator: checkOutPrice,
            required: true,
            trigger: "blur",
          },
        ],
        ppNumber: [
          {
            required: true,
            trigger: "change",
          },
        ],
        supplier: [
          {
            required: true,
            trigger: "change",
          },
        ],
        arrivalDate: [
          {
            required: true,
            trigger: "change",
          },
        ],
        // arrivalDate
      },
    };
  },
  activated() {
    //参数是否有值
    if (this.initialStatus == true) {
      this.initialStatus = false;
      return;
    }
    if (
      (this.entry.timeStamp !== this.$route.query.timeStamp &&
        this.$route.query.open == "addStatus") ||
      this.$route.query.fmConfig !== this.entry.setConfig||
      this.$route.query.needType !== this.entry.setNeedType
    ) {
      this.Initial();
      return;
    }
   
    if (this.entry.seeCode !== this.$route.query.detailCode) {
      if (
        this.fmStatus == "seeStatus" &&
        this.$route.query.open !== "addStatus"
      ) {
        this.Initial();
        return;
      }
    }

    if (this.entryMode == true) {
      if (this.fmData.workType !== this.$route.query.workType) {
        this.Initial();
      } else if (this.$route.query.workType == "") {
        this.entryMode = false;
        this.Initial();
      }
    } else {
      if (this.$route.query.workType != "") {
        this.entryMode = true;
        this.Initial();
      }
    }
  },

  created() {
    //初始化页面
    this.initialStatus = true;
    this.Initial();
  },
  methods: {
    Initial() {
      // 按钮状态
      this.fmStatus = this.$route.query.open;
      this.entry.setConfig = this.$route.query.fmConfig;
      this.entry.setNeedType = this.$route.query.needType;
      this.entry.timeStamp = this.$route.query.timeStamp;
      if (this.fmStatus == "addStatus") {
        //新增状态重置表单
        this.objHelper.handleReset();
      }
      this.getDictionaryType().then((res) => {
        this.objHelper.getParameters().then(() => {
          if (this.fmStatus == "seeStatus" || this.fmStatus == "updateStatus") {
            this.entry.seeCode = this.$route.query.detailCode;
            seeBill({
              poCode: this.entry.seeCode,
            }).then((res) => {
              if (res.code == 200) {
                this.fmData = res.data;
                if (this.fmData.workStatus == "1") {
                  this.stack.commandIndex = "1";
                } else if (this.fmData.workStatus == "2") {
                  this.stack.commandIndex = "2";
                } else {
                  this.stack.commandIndex = "0";
                }
                this.stack.uploadList = this.fmData.poAttachmentList;
                this.objUpload.isPdf();
                this.objUtils.getDecimal();
                if (this.fmData.workDept !== "") {
                  // 部门数据回显
                  this.objHelper.undataAddSee(this.fmData.workDept);
                }
                // 业务人员
                this.stack.selectworkStaff = this.fmData.workStaff;
                if (this.fmStatus == "seeStatus") {
                  this.option.disabledInput = true;
                  this.option.wmworkStatus = true; //编辑状态下业务类型
                } else {
                  this.option.disabledInput = false;
                  if (this.entryMode == true) {
                    this.option.wmworkStatus = true;
                  } else {
                    this.option.wmworkStatus = false;
                  }
                }
              }
            });
          }
        });
      });

      // 路由信息用于关闭页面
      this.entry.routeMsg = this.$route;
      if (
        this.$route.query.workType !== "" &&
        this.$route.query.fmConfig !== ""
      ) {
        this.entryMode = true; //参数有值时
      } else {
        this.entryMode = false; //参数无值时
      }

      // 物料信息最大高度
      if (`${document.documentElement.clientHeight}` - 440 < 400) {
        this.style.tableHeight = 500;
      } else {
        this.style.tableHeight =
          `${document.documentElement.clientHeight}` - 430;
      }
    },

    // 获取字典数据
    getDictionaryType() {
      return new Promise((resolve) => {
        const _self = this;
        _self.loading = false;
        //并行请求
        axios
          .all([
            // 单据类型
            dictMatching("po_invoice_type"),
            // 业务类型
            dictMatching("po_order_type"),
            // 业务状态
            dictMatching("sys_work_status"),
            // 部门
            listDept(),
            //用料需求
            dictMatching("mp_need_type"),
            //子用料方式
            dictMatching("inv_in_type"),
          ])
          .then(
            axios.spread(function (
              resIvType,
              resOrderType,
              resWorkStatus,
              resDept,
              resNeedType,
              resInvInType
            ) {
              if (
                resIvType.code == 200 &&
                resOrderType.code == 200 &&
                resWorkStatus.code == 200 &&
                resDept.code == 200
              ) {
                // 单据类型
                _self.enums.optionsInvoiceType = resIvType.data;
                // 业务类型
                _self.enums.optionsworkType = resOrderType.data;
                // 业务部门
                let arr = _self.handleTree(resDept.data, "deptId");
                _self.enums.optionsworkDept = getTreeData(arr);
                //业务状态
                _self.enums.optionsworkStatus = resWorkStatus.data;
                //用料需求
                _self.enums.optionsNeedType = resNeedType.data;
                //子用料方式
                _self.enums.optionsinvInType = resInvInType.data;
                console.log(_self.enums.optionsinvInType);
                //新增状态
                if (_self.fmStatus == "addStatus") {
                  _self.loading = false;
                  _self.fmData.invoiceDate = new Date();
                  _self.fmData.warehouseOper = _self.$store.getters.name;
                }

                if (_self.$route.query.workType == "") {
                  if (_self.fmStatus == "addStatus") {
                    _self.fmData.workType =
                      _self.enums.optionsworkType[0].dictValue;
                  }
                } else {
                  _self.style.pageTitle =
                    _self.enums.optionsworkType[
                      _self.$route.query.workType
                    ].dictLabel;
                  _self.fmData.workType =
                    _self.enums.optionsworkType[
                      _self.$route.query.workType
                    ].dictValue;
                }
                resolve();
              } else {
                _self.msgError("获取信息失败");
              }
            })
          );
      });
    },

    //确定新增
    btnNew(fmData) {
      if (this.fmData.poOrderSalveList.length == 0) {
        this.msgError("物料信息为空");
      } else {
        this.$refs.fmData.validate((valid) => {
          if (valid) {
            fmData.invoiceDate = this.parseTime(fmData.invoiceDate);
            fmData.arrivalDate = this.parseTime(fmData.arrivalDate);
            fmData.poOrderSalveList.forEach((value) => {
              fmData.poAttachmentList = this.stack.uploadList;
              if (
                value.ppDate !== "" &&
                value.ppDate !== null &&
                value.ppDate !== undefined
              ) {
                value.ppDate = this.parseTime(new Date(value.ppDate));
              } else {
                value.ppDate = null;
              }
              if (
                value.woDate !== "" &&
                value.woDate !== null &&
                value.woDate !== undefined
              ) {
                value.woDate = this.parseTime(new Date(value.woDate));
              } else {
                value.woDate = null;
              }
            });
            if (this.$route.query.fmConfig !== undefined) {
              fmData.formConfig = this.$route.query.fmConfig;
            }
            addBill(fmData)
              .then((res) => {
                this.msgSuccess("新增成功");
                // 更新成功不刷新,重新赋值表单数据
                this.option.btnIsClick = true;
                this.fmStatus = "seeStatus";
                this.option.disabledInput = true;
                this.fmData = res.data;
                this.option.wmworkStatus = true;
                this.$store.dispatch("purchaseStatus/setOrderRefresh", true);
                this.stack.uploadList = this.fmData.poAttachmentList;
                this.objUpload.isPdf();
                this.objUtils.getDecimal();
              })
              .catch((err) => {
                this.msgError("新增失败");
              });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      }
    },

    // 更新保存
    btnSave(fmData) {
      if (this.fmData.poOrderSalveList.length == 0) {
        this.msgError("物料信息为空");
      } else {
        this.$refs.fmData.validate((valid) => {
          if (valid) {
            fmData.invoiceStatus = "0";
            fmData.invoiceDate = this.parseTime(fmData.invoiceDate);
            fmData.arrivalDate = this.parseTime(fmData.arrivalDate);
            fmData.poOrderSalveList.forEach((value) => {
              if (
                value.ppDate !== "" &&
                value.ppDate !== null &&
                value.ppDate !== undefined
              ) {
                value.ppDate = this.parseTime(new Date(value.ppDate));
              } else {
                value.ppDate = null;
              }
              if (
                value.woDate !== "" &&
                value.woDate !== null &&
                value.woDate !== undefined
              ) {
                value.woDate = this.parseTime(new Date(value.woDate));
              } else {
                value.woDate = null;
              }
            });
            updateBill(fmData)
              .then((res) => {
                this.msgSuccess("更新成功");
                this.fmStatus = "seeStatus";
                this.option.disabledInput = true;
                this.fmData = res.data;
                this.stack.uploadList = this.fmData.poAttachmentList;
                this.objUpload.isPdf();
                this.option.wmworkStatus = true;
                this.$store.dispatch("purchaseStatus/setOrderRefresh", true);
                this.objUtils.getDecimal();
              })
              .catch((err) => {
                this.msgError("更新失败");
              });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      }
    },

    //查看->编辑
    btnEdit() {
      this.option.disabledInput = false;
      this.fmStatus = "updateStatus";
      this.$nextTick(() => {
        //切换，重新渲染表格防止抖动
        this.$refs["tableClums"].doLayout();
      });
      this.option.btnIsClick = false;
      if (this.entryMode == true) {
        this.option.wmworkStatus = true;
      } else {
        this.option.wmworkStatus = false;
      }
    },

    //查看->新增
    btnAdd(type) {
      if (type == "view") {
        this.$router.push({
          path: "/po/purchase/orderadd",
          query: {
            open: "addStatus",
            workType: this.$route.query.workType,
            fmConfig: this.$route.query.fmConfig,
            needType: this.fmData.needType,
            timeStamp: new Date().getTime()
          },
        });
      } else {
        this.fmStatus = "addStatus"; //按钮状态为新增
        this.option.disabledInput = false; //输入框可输入
        this.option.btnIsClick = false; //按钮状态为可点击
        this.enums.selectworkDept = ""; //清空采购部门选择
        this.stack.selectworkStaff = ""; //清空采购人员
        this.objHelper.handleReset(); //重置表单默认值
        if (this.entryMode == true) {
          this.option.wmworkStatus = true;
        } else {
          this.option.wmworkStatus = false;
        }
        this.$refs.fmData.clearValidate();
      }
    },

    //撤回
    btnUndo() {
      this.option.disabledInput = true; //是否可编辑
      this.workStatus = true;
      this.$nextTick(() => {
        //切换，重新渲染表格防止抖动
        this.$refs["tableClums"].doLayout();
      });
      this.fmStatus = "seeStatus";
      this.option.disabledInput = true;
      this.option.wmworkStatus = true;
    },

    //新增->取消
    btnCancel() {
      const self = this;
      self.$store
        .dispatch("tagsView/delView", self.entry.routeMsg)
        .then(({ visitedViews }) => {
          let cancelFun = {
            isActive(route) {
              return route.path === self.$route.path;
            },
            toLastView(visitedViews, view) {
              const latestView = visitedViews.slice(-1)[0];
              if (latestView) {
                self.$router.push(latestView.fullPath);
              } else {
                if (view.name === "Dashboard") {
                  self.$router.replace({
                    path: "/redirect" + view.fullPath,
                  });
                } else {
                  self.$router.push("/");
                }
              }
            },
          };
          if (cancelFun.isActive(this.entry.routeMsg)) {
            cancelFun.toLastView(visitedViews, this.entry.routeMsg);
          }
        });
    },

    //操作
    btnOperation(value) {
      let data = {
        poCode: this.fmData.poCode,
        workStatus: value,
        version: this.fmData.version,
      };
      operationBill(data).then((res) => {
        if (res.code == 200) {
          this.fmData.workStatus = res.data.workStatus;
          this.stack.commandIndex = res.data.workStatus;
          this.fmData.version = res.data.version;
          this.msgSuccess("状态修改成功");
        }
      });
    },

    //审核
    btnCheck() {
      examineBill([
        {
          poCode: this.fmData.poCode,
        },
      ]).then((res) => {
        if (res.code == 200) {
          this.fmData.invoiceStatus = "1";
          this.fmData.checkDate = res.data.checkDate;
          this.fmData.userCheck = res.data.userCheck;
          this.msgSuccess("审核成功");
        }
      });
    },

    //反审核
    btnUnCheck() {
      this.$confirm("确定撤销审核", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return examineDeBill([
            {
              poCode: this.fmData.poCode,
            },
          ]);
        })
        .then((res) => {
          if (res.code == 200) {
            this.fmData.invoiceStatus = "2";
            this.fmData.checkDate = "";
            this.fmData.userCheck = "";
            this.msgSuccess("撤销成功");
          }
        });
    },

    // 上一条下一条
    btnForward(code, type) {
      this.option.parametersStatus = false;
      if (type == "next") {
        this.option.stripStatus = true;
        NextBill({
          poCode: code,
          workType: this.$route.query.workType,
          type: true,
        })
          .then((res) => {
            if (res.code == 200) {
              this.fmData = res.data;
              this.$refs["tableClums"].doLayout();
              this.option.parametersStatus = true;
              this.getDictionaryType();
              this.objUtils.getDecimal();
              this.option.stripStatus = false;
            }
          })
          .catch((err) => {
            this.option.parametersStatus = true;
            this.option.stripStatus = false;
          });
      } else {
        this.option.stripStatus = true;
        NextBill({
          poCode: code,
          workType: this.$route.query.workType,
          type: false,
        })
          .then((res) => {
            if (res.code == 200) {
              this.fmData = res.data;
              this.$refs["tableClums"].doLayout();
              this.option.parametersStatus = true;
              this.getDictionaryType();
              this.objUtils.getDecimal();
              this.option.stripStatus = false;
            }
            console.log(1);
          })
          .catch((err) => {
            this.option.parametersStatus = true;
            this.option.stripStatus = false;
          });
      }
    },

    //物料信息
    classMaterial() {
      const self = this;
      return {
        // 新增物料
        addMaterial() {
          self.stack.saveIndex = null;
          self.fmData.poOrderSalveList.push({
            ...self.fmItem,
          });
        },

        // 物料搜索
        searchCode(index, data) {
          self.stack.rowIndex = index;
          if (self.fmData.poOrderSalveList[index].invCode !== "") {
            self.fmData.poOrderSalveList[index].invName = "";
            self.fmData.poOrderSalveList[index].invAttribute = "";
            self.fmData.poOrderSalveList[index].unitName = "";
            self.query.code = this.fmData.poOrderSalveList[index].invCode;
            this.getMaterialList();
            self.stack.saveIndex = index;
          }
        },

        // 获取物料数据
        getMaterialList() {
          self.stack.basicfileList = [];
          listMaterial(self.query).then((res) => {
            self.stack.basicfileList = res.rows;
          });
        },

        //当搜索编码只有一条物料信息回车键直接选择
        codeEnter() {
          if (self.stack.basicfileList.length == 1) {
            let arr = [false];
            arr.unshift(self.stack.basicfileList[0]);
            this.handleSelect(arr);
            self.stack.saveIndex = null;
          }
        },

        // 选择成功
        successSelect(data) {
          let arr = [false];
          arr.unshift(data);
          this.handleSelect(arr);
          self.stack.saveIndex = null;
        },

        //显示物料选择框
        btnItem(index) {
          self.stack.saveIndex = null;
          self.stack.selectDialog = true;
          self.stack.rowIndex = index;
        },

        //关闭物料搜索下拉
        handleHide() {
          self.stack.saveIndex = null;
        },

        //选择物料
        handleSelect(data) {
          self.stack.saveIndex = null;
          let selectObj = {
            invSortId: data[0].sortId,
            invCode: data[0].code,
            invName: data[0].name,
            invAttribute: data[0].attribute,
            unitName: data[0].unitName,
            unitCode: data[0].unitCode,
            invSortRoot: data[0].sortRoot,
            quantity: "", //采购数量
            price: "", //采购单价
            amount: "0.00", //采购金额
            ppNumber: "",
            ppDate: null,
            salesman: "",
            woCode: "", //上游单据
            woUniqueId: 0, //上游物料
            woQantity: "",
            wiQantity: "",
            remarks: "", //备注
          };
          if (data[1] == false) {
            // 更新表单数据
            self.$set(self.fmData.poOrderSalveList, self.stack.rowIndex, {
              salesman:
                self.fmData.poOrderSalveList[self.stack.rowIndex].salesman,
              ppNumber:
                self.fmData.poOrderSalveList[self.stack.rowIndex].ppNumber,
              ppDate: self.fmData.poOrderSalveList[self.stack.rowIndex].ppDate,
              remarks:
                self.fmData.poOrderSalveList[self.stack.rowIndex].remarks,
              needDate:
                self.fmData.poOrderSalveList[self.stack.rowIndex].needDate,

              invSortId: data[0].sortId,
              invCode: data[0].code,
              invName: data[0].name,
              invAttribute: data[0].attribute,
              unitName: data[0].unitName,
              unitCode: data[0].unitCode,
              invSortRoot: data[0].sortRoot,
              price: "",
              quantity: "",
              woInvoice: "",
              woInvoiceId: "",
              woType: "",
              woTypeId: "",
              woConfig: "",
              woDate: null,
              woCode: "", //上游单据
              woUniqueId: 0, //上游物料
              woQantity: "", //上游数量
              wiQantity: "", //下游数量
            });
            this.selectClose();
          } else {
            if (data[2] == 1) {
              self.$set(self.fmData.poOrderSalveList, self.stack.rowIndex, {
                salesman:
                  self.fmData.poOrderSalveList[self.stack.rowIndex].salesman,
                ppNumber:
                  self.fmData.poOrderSalveList[self.stack.rowIndex].ppNumber,
                ppDate:
                  self.fmData.poOrderSalveList[self.stack.rowIndex].ppDate,
                remarks:
                  self.fmData.poOrderSalveList[self.stack.rowIndex].remarks,
                needDate:
                  self.fmData.poOrderSalveList[self.stack.rowIndex].needDate,

                invSortId: data[0].sortId,
                invCode: data[0].code,
                invName: data[0].name,
                invAttribute: data[0].attribute,
                unitName: data[0].unitName,
                unitCode: data[0].unitCode,
                invSortRoot: data[0].sortRoot,
                price: "",
                quantity: "",
                woInvoice: "",
                woInvoiceId: "",
                woType: "",
                woTypeId: "",
                woConfig: "",
                woDate: null,
                woCode: "", //上游单据
                woUniqueId: 0, //上游物料
                woQantity: "", //上游数量
                wiQantity: "", //下游数量
              });
            } else {
              self.fmData.poOrderSalveList.push({
                ...selectObj,
              });
            }
          }
        },

        // 选择物料弹框状态
        selectClose() {
          self.stack.selectDialog = false;
        },

        // 删除
        deleteList(index) {
          self.$message({
            message: "删除成功",
            duration: 1000,
          });
          self.fmData.poOrderSalveList.splice(index, 1);
          self.stack.saveIndex = null;
        },

        // 选择引入物料
        handleImportMaterialSelect(code, index) {
          self.stack.ImportMaterialStatus = true;
          self.$refs.fmData.clearValidate();
        },
        handdleAddImport(list) {
          return new Promise((resolve, reject) => {
            let materialDate = {
              invSortId: "", //物料分类
              invCode: "", //物料编码
              invName: "", //物料名称
              invAttribute: "", //型号规格
              unitCode: "", //主计量
              unitName: "", //主计量
              quantity: "", //采购数量
              price: "", //采购单价
              amount: "0.00", //采购金额
              ppNumber: "",
              ppDate: null,
              salesman: "",
              needDate: null,
              woInvoice: "",
              woInvoiceId: "",
              woType: "",
              woTypeId: "",
              woDate: null,
              woConfig: "",
              woQuantity: "", //上游数量
              wiQuantity: "", //下游数量
              woCode: "", //上游单据
              woUniqueId: "", //上游物料
              remarks: "", //备注
            };
            let successList = JSON.parse(JSON.stringify(list)),
              formMaterial = []; //赋值物料信息
            successList.forEach((item, i) => {
              formMaterial.push({
                ...materialDate,
              });
            });
            resolve(formMaterial);
          });
        },

        // 选择引入物料成功
        handleImportMaterialSuccess(list) {
          this.handdleAddImport(list).then((arr) => {
            let successList = JSON.parse(JSON.stringify(list));
            if (successList.length > 0) {
              for (let i = 0; i < successList.length; i++) {
                arr[i].salesman = successList[i].salesman;
                arr[i].ppNumber = successList[i].pp_number;
                arr[i].ppDate = successList[i].pp_date || null;
                arr[i].needDate = successList[i].need_date || null;
                arr[i].invSortRoot = successList[i].inv_sort_root;
                arr[i].invSortId = successList[i].inv_sort_id;
                arr[i].invCode = successList[i].inv_code;
                arr[i].invName = successList[i].inv_name;
                arr[i].unitName = successList[i].unit_name;
                arr[i].unitCode = successList[i].unit_code;
                arr[i].invAttribute = successList[i].inv_attribute;
                arr[i].woInvoice = successList[i].invoice_type;
                arr[i].woInvoiceId = successList[i].invoice_type_id;
                arr[i].woType = successList[i].work_type;
                arr[i].woTypeId = successList[i].work_type_id;
                arr[i].woDate = successList[i].invoice_date || null;
                arr[i].woConfig = successList[i].form_config;
                arr[i].woCode = successList[i].mp_code;
                arr[i].remarks = successList[i].remarks;
                arr[i].woUniqueId = successList[i].unique_id;
                arr[i].quantity = successList[i].surplus || "";
                arr[i].woQuantity = successList[i].surplus;
              }
            }
            self.fmData.poOrderSalveList.push(...arr);
          });
        },
        //关闭引入组件
        selectImportMaterialClose() {
          self.stack.ImportMaterialStatus = false;
        },
      };
    },

    //供方
    classSupplier() {
      const self = this;
      return {
        //获取供方
        getSupplierlList(data) {
          listSupplier({
            name: data,
            status: "0",
          }).then((res) => {
            if (res.code == 200) {
              self.stack.poSearchStatus = true;
              self.stack.optionssupplier = res.rows;
            }
          });
        },
        //供方/选择
        handlePoPuPrs(type) {
          if (type == "po") {
            //供应商
            self.stack.poStatus = true;
          }
        },

        //选择成功
        successPoPuPrs(data, type) {
          if (type == "poSearch") {
            self.fmData.supplier = data.name;
            self.fmData.supplierId = data.code;
            self.stack.poSearchStatus = false;
          }
        },

        //供应商搜索
        searchPoPuPrs(data, type) {
          if (type == "poSearch") {
            this.getSupplierlList(data);
          }
        },

        //搜索条数为1
        nameEnter(data, type) {
          if (type == "poSearch" && self.stack.optionssupplier.length == 1) {
            this.successPoPuPrs(self.stack.optionssupplier[0], type);
          }
        },

        //关闭
        handleClosePoPuPrs(type) {
          if (type == "poSearch") {
            self.stack.poSearchStatus = false;
          }
        },

        // 供方组件关闭
        selectSupplierClose() {
          self.stack.poStatus = false;
        },

        //供方组件选择成功
        handleSupplierSelect(row) {
          self.fmData.supplier = row.name;
          self.fmData.supplierId = row.uniqueId;
          self.stack.poStatus = false;
        },
      };
    },

    //打印
    classPrinter() {
      const self = this;
      return {
        //打印
        handlePrint() {
          let transferData = JSON.parse(JSON.stringify(self.fmData));
          self.print.qrCodeValue = `po_invoice_type=2&po_order_type=${transferData.workType}&code=${transferData.poCode}`;
          //业务类型
          self.enums.optionsworkType.forEach((obj) => {
            if (obj.dictValue == transferData.workType) {
              transferData.workTypeTran = obj.dictLabel + "订单";
            }
          });
          //用料方式
          self.enums.optionsNeedType.forEach((obj) => {
            if (obj.dictValue == transferData.needType) {
              transferData.needType = obj.dictLabel;
            }
          });
          //部门
          transferData.workDept = self.print.printWorkDept.join("/");
          self.print.printData = transferData;
          let number = 1;
          self.print.printData.poOrderSalveList.forEach((obj) => {
            obj.id = number++;
          });
          self.print.printData.printTime = self.parseTime(new Date());
          self.print.printStatus = true;
          setTimeout(() => {
            this.getTitle().then(() => {
              self.$print(self.$refs.startPrint.$refs.print);
            });
          }, 50);
        },
        //获取模块参数中对应的打印标题
        getTitle() {
          return new Promise((resolve) => {
            moduleParameters({
              moduleId: "sys",
            })
              .then((res) => {
                if (res.code == 200) {
                  const obj = res.rows.find((item) => {
                    return item.configKey == "sys.title.print";
                  });
                  self.print.printTitle = obj.configValue;
                  resolve();
                }
              })
              .catch(() => {
                self.msgError("获取模块参数失败");
              });
          });
        },
      };
    },

    //助手
    classHelper() {
      const self = this;
      return {
        //获取单据参数
        getParameters() {
          return new Promise((resolve, reject) => {
            billParameters({
              formPath: self.$route.query.fmConfig,
            }).then((res) => {
              if (res.code == 200) {
                if (res.data["precision.quantity"] !== "null") {
                  self.fmConfig.decimalQuantity =
                    res.data["precision.quantity"];
                }
                if (res.data["precision.price"] !== "null") {
                  self.fmConfig.decimalPrice = res.data["precision.price"];
                }
                if (res.data["inv.attr.merge"] !== "null") {
                  self.fmConfig.attrMerge = res.data["inv.attr.merge"];
                }

                if (res.data["inv.attr.alias"] !== "null") {
                  self.fmConfig.attrAlias = res.data["inv.attr.alias"];
                }
                if (res.data["inv.scope"] !== "null") {
                  let arr = res.data["inv.scope"].split(",");
                  self.fmConfig.sortArrId = arr;
                }

                //特殊属性
                if (res.data["inv.property"] !== "null") {
                  self.fmConfig.property = res.data["inv.property"].split(",");
                }
                setTimeout(() => {
                  if (self.fmStatus == "addStatus") {
                    //切换，重新渲染表格防止抖动
                    self.$refs["tableClums"].doLayout();
                  }
                  self.option.parametersStatus = true;
                }, 50);
                resolve();
              }
            });
          });
        },

        // 业务类型选择
        workTypeChange(value) {
          self.fmData.workType = value;
        },

        //业务部门选择
        workDeptChange(value) {
          let deptId = JSON.parse(JSON.stringify(value)); //防止干扰级联选择器
          self.fmData.workDept = deptId.pop();
          self.stack.selectworkStaff = "";
          self.fmData.workStaff = "";
          listUser({
            deptId: self.fmData.workDept,
          }).then((res) => {
            self.stack.optionsworkStaff = res.rows;
          });
        },

        //业务人员选择
        workStaffChange(value) {
          self.fmData.workStaff = self.stack.selectworkStaff;
        },

        //切换计划方式
        needTypeChange() {
          self.fmData.poOrderSalveList = [];
          self.$nextTick(() => {
            //切换，重新渲染表格防止抖动
            self.$refs["tableClums"].doLayout();
          });
        },

        // 部门数据回显
        undataAddSee(id) {
          return new Promise((resolve, reject) => {
            let parentArr = [], //用于储存父类部门信息
              childrenArr = []; //用于储存子类部门信息
            getEcho(
              id,
              self.enums.optionsworkDept,
              parentArr,
              childrenArr
            ).then((res) => {
              setTimeout(() => {
                let success = [];
                for (let i = 0; i < res.length; i++) {
                  if (success.indexOf(res[i]) === -1) {
                    success.push(res[i]);
                  }
                }
                let getNode = JSON.parse(JSON.stringify(success)); //拷贝vuex信息，避免影响源数据
                getNode.forEach((v) => {
                  if (v.ancestors.indexOf(",") > -1) {
                    //是否是子部门
                    v.ancestors = v.ancestors.split(",").length; //拼接数组长度，用于排序
                  } else {
                    v.ancestors = 1;
                  }
                });
                getNode.sort((a, b) => {
                  //排序得到正常的部门顺序
                  return a.ancestors - b.ancestors;
                });
                self.enums.selectworkDept = [];
                self.print.printWorkDept = [];
                getNode.forEach((code) => {
                  self.enums.selectworkDept.push(code.deptId);
                  self.print.printWorkDept.push(code.deptName);
                });
              }, 0);
            });
            resolve();
          });
        },

        //收起
        downToggle() {
          self.stack.saveIndex = null;
          if (self.style.downTitle == "收起") {
            self.style.downTitle = "展开";
          } else {
            self.style.downTitle = "收起";
          }
          self.style.isToggle = !self.style.isToggle;
          if (self.style.isToggle == false) {
            self.style.tableHeight = parseInt(self.style.tableHeight) + 170;
          } else {
            self.style.tableHeight =
              `${document.documentElement.clientHeight}` - 440;
          }
        },

        //点击新增/查看新增重置表单
        handleReset() {
          self.fmData = {
            invoiceDate: new Date(), //单据日期
            invoiceStatus: "0", //单据状态
            invoiceType: "1", //单据类型
            workStatus: "0", //业务状态
            workType: "", //业务类型
            contract: "", //上传地址
            formConfig: "",
            contractName: "", //上传名称
            userOper: self.$store.getters.name,
            workDept: "", //业务部门
            workStaff: "", //业务人员
            checkDate: "", //审核日期
            userCheck: "",
            needType: self.$route.query.needType, //用料方式
            supplier: "", //供方
            supplierId: "", //供方
            poCode: "", //单据编码
            remarks: "", //备注
            poOrderSalveList: [],
          };
          self.stack.selectworkStaff = "";
          self.stack.uploadList = [];
          /* 初始化状态 */
          self.option.disabledInput = false;
          self.workStatus = false;
          self.option.btnIsClick = false;
          self.option.wmworkStatus = false;
          self.enums.selectworkDept = "";
          self.workStaff = "";
        },
      };
    },

    //工具
    classUtils() {
      const self = this;
      return {
        //格式化用户输入价格单价小数位数
        formatDecimal(index, data) {
          self.stack.rowIndex = index;
          if (
            self.fmData.poOrderSalveList[index].price !== "" &&
            isAccord(self.fmData.poOrderSalveList[index].price)
          ) {
            let price = self.fmData.poOrderSalveList[index].price;
            self.fmData.poOrderSalveList[index].price = parseFloat(
              price
            ).toFixed(self.fmConfig.decimalPrice);
          }
          if (
            self.fmData.poOrderSalveList[index].quantity !== "" &&
            isAccord(self.fmData.poOrderSalveList[index].quantity)
          ) {
            let quantity = self.fmData.poOrderSalveList[index].quantity;
            self.fmData.poOrderSalveList[index].quantity = parseFloat(
              quantity
            ).toFixed(self.fmConfig.decimalQuantity);
          }
          if (
            self.fmData.poOrderSalveList[index].price !== "" &&
            self.fmData.poOrderSalveList[index].quantity !== "" &&
            isAccord(self.fmData.poOrderSalveList[index].price) &&
            isAccord(self.fmData.poOrderSalveList[index].quantity)
          ) {
            self.fmData.poOrderSalveList[index].amount = (
              self.fmData.poOrderSalveList[index].price *
              self.fmData.poOrderSalveList[index].quantity
            ).toFixed(2);
          } else {
            self.fmData.poOrderSalveList[index].amount = "0.00";
          }
        },

        //格式化数量单价金额小数位数
        getDecimal() {
          self.fmData.poOrderSalveList.forEach((item) => {
            if (item.price !== null && item.price !== undefined) {
              item.price = parseFloat(item.price).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
            if (item.quantity !== null && item.quantity !== undefined) {
              item.quantity = parseFloat(item.quantity).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
            if (item.amount !== null && item.amount !== undefined) {
              item.amount = parseFloat(item.amount).toFixed(2);
            }
            if (item.wmQuantity !== null && item.wmQuantity !== undefined) {
              item.wmQuantity = parseFloat(item.wmQuantity).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
            if (
              item.orderQuantity !== null &&
              item.orderQuantity !== undefined
            ) {
              item.orderQuantity = parseFloat(item.orderQuantity).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
            if (item.wiQuantity !== null && item.wiQuantity !== undefined) {
              item.wiQuantity = parseFloat(item.wiQuantity).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
            if (item.woQuantity !== null && item.woQuantity !== undefined) {
              item.woQuantity = parseFloat(item.woQuantity).toFixed(
                self.fmConfig.decimalQuantity
              );
            }
          });
        },

        //时间格式转换
        inMaterTime(date) {
          let time = new Date(date);
          return (
            time.getFullYear() +
            "-" +
            (time.getMonth() + 1) +
            "-" +
            time.getDate() +
            " " +
            time.getHours() +
            ":" +
            time.getMinutes() +
            ":" +
            time.getSeconds()
          );
        },

        //解决级联选择器回显高亮异常问题
        resetSelector() {
          if (self.$refs.classTree) {
            self.$refs.classTree.$refs.panel.activePath = [];
            self.$refs.classTree.$refs.panel.calculateCheckedNodePaths();
          }
        },
      };
    },

    //上传
    classUpload() {
      const self = this;
      return {
        //上传按钮操作
        handleUpload() {
          self.upload.title = "上传采购合同";
          self.upload.open = true;
        },

        handleUploadChange(file, fileList) {
          self.upload.fileList = fileList;
        },

        submitFileForm() {
          let formData = new FormData(); //  用FormData存放上传文件
          self.upload.fileList.forEach((file) => {
            formData.append("file", file.raw);
          });
          uploadFiles(formData).then((res) => {
            if (res.code == 200) {
              self.stack.uploadList.push(...res.data.data);
              self.upload.open = false;
              self.$refs.upload.clearFiles();
              self.msgSuccess("上传成功");
              self.objUpload.isPdf();
            }
          });
        },

        //合同显示下载预览删除
        mouseenter(data) {
          self.$set(data, "opShow", true);
        },
        mouseleave(data) {
          self.$set(data, "opShow", false);
        },

        //下载合同
        handleDownload(fileName, path) {
          let url = process.env.VUE_APP_BASE_API;
          const link = document.createElement("a");
          link.setAttribute("download", fileName);
          link.setAttribute(
            "href",
            process.env.VUE_APP_BASE_API +
              `/po/order/download?fileName=${fileName}&path=${path}`
          );
          link.click();
        },
        handleExceed(files, fileList) {
          self.$message.warning(
            `当前限制选择 5 个文件，本次选择了 ${
              files.length
            } 个文件，共选择了 ${files.length + fileList.length} 个文件`
          );
        },
        //删除已上传
        handleDeleteImport(index) {
          self.stack.uploadList.splice(index, 1);
        },

        //是否为pdf文件
        isPdf() {
          let index = "",
            format = "";
          if (self.stack.uploadList.length > 0) {
            self.stack.uploadList.forEach((item) => {
              index = item.path.lastIndexOf(".");
              format = item.path.substr(index + 1);
              if (format == "pdf" || format == "PDF") {
                item.pdfStatus = true;
              }
            });
          }

          console.log(self.stack.uploadList);
        },

        //预览合同
        handlePreview(fileName, path) {
          let url = process.env.VUE_APP_BASE_API;
          const link = document.createElement("a");
          link.href =
            process.env.VUE_APP_BASE_API +
            `/po/order/download?fileName=${fileName}&path=${path}`;
          // link.target = "_blank";
          link.click();
        },
        closeUpload() {
          self.$refs.upload.clearFiles();
        },
      };
    },
  },

  filters: {
    getInvoice(status) {
      switch (status) {
        case "0":
          return "开立";
          break;
        case "1":
          return "审核";
          break;
        case "2":
          return "退回";
          break;
        default:
          return "无";
      }
    },
  },
  components: {
    selectMaterial,
    selectSupplier,
    selectImportMaterial,
    PrintPage,
  },
  watch: {},
};
</script>

<style lang="scss">
.menu-drop-box {
  .el-dropdown-menu__item {
    width: 90px;
    text-align: center;
    position: relative;

    span {
      display: inline-block;
    }

    i {
      position: absolute;
      left: 15px;
      top: 7px;
    }
  }

  .active {
    i,
    span {
      color: #46a6ff;
    }
  }
}
.bill-box {
  .box-add {
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    width: 210px;
    align-items: center;
    background-color: #fff;
    border: 1px solid #dfe4ed;
    border-radius: 5px;
    margin-bottom: 2px;
    height: 32px;
    .el-link {
      height: 20px;
    }

    .el-input__inner {
      width: 145px !important;
      background: none;
      border: none;
      padding-left: 0;
      padding-right: 0;
    }
    .om-see .el-input__inner {
      width: 180px !important;
    }
  }
  .is-error .box-add {
    border: 1px solid #ff4949;
  }
  .el-textarea__inner {
    font-size: 14px;
    color: #303133;
    padding: 5px 10px !important;
  }
  .piece-box {
    .el-icon-date {
      display: none;
    }
  }
  .sc-upload {
    display: flex;
    margin-bottom: 5px;

    p {
      margin-top: 0;
      margin-bottom: 0;
      font-size: 14px;
      line-height: 32px;
    }
    .bac-uplode {
      background-color: #f5f7fa;
    }
    .box-upload {
      width: 210px;
      min-height: 32px;
      border: 1px solid #dcdfe6;
      padding: 5px 0;
      border-radius: 5px;
      position: relative;
      .el-link {
        position: absolute;
        right: 10px;
        top: 0;
      }
      .upload-con {
        display: flex;
        margin-top: 5px;
        margin-bottom: 5px;
        align-items: center;
        height: 20px;
        padding-right: 35px;

        label {
          flex-shrink: 1;
          width: 14px;
          font-size: 14px;
          cursor: pointer;

          i {
            margin-left: 2px;
            margin-right: 2px;

            &:hover {
              font-weight: 700;
            }
          }
        }

        span {
          font-size: 13px;
          display: block;
          margin-left: 5px;
          margin-right: 5px;
          cursor: pointer;
          line-height: 15px;

          i {
            padding-right: 3px;
          }

          &:hover {
            color: #1890ff;
          }
        }
      }
    }
  }

  .code-red {
    input {
      color: #fc6a6a !important;
    }
  }

  .el-textarea.is-disabled .el-textarea__inner {
    color: #333;
  }

  .input-pp {
    .el-icon-date,
    .el-input__icon {
      line-height: 30px !important;
    }

    .el-input__inner {
      font-size: 13px;
    }
  }

  .code-yellow {
    input {
      color: #e6a23c !important;
    }
  }

  .purchas-information {
    .el-card__body {
      padding: 15px 20px 10px 20px;
    }

    .el-input__inner,
    .el-textarea__inner {
      width: 210px;
    }
  }

  .set-location {
    display: flex;
    align-items: center;

    .location-btn {
      flex-shrink: 1;
      width: 40px;
      margin-right: 5px;
      height: 20px;
    }
  }

  .el-card.is-always-shadow {
    overflow: inherit;
  }

  .blue-red {
    label:nth-of-type(2) {
      .is-checked .el-radio__inner {
        background: #fc6a6a;
        border-color: #fc6a6a;
      }

      .is-checked + .el-radio__label {
        color: #fc6a6a;
      }

      font-size: 20px;
    }
  }

  .unfold-way {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;

    p {
      margin: 0;
      margin-bottom: 8px;
    }
  }

  .con-spec {
    display: flex;
    text-align: center;
    justify-content: center;
    word-wrap: break-word;

    .spec-l {
      padding-right: 2px;

      input {
        text-align: right !important;
      }
    }

    .spec-r {
      input {
        text-indent: 0 !important;
        text-align: left !important;
      }
    }
  }

  .el-radio__input.is-disabled.is-checked .el-radio__inner {
    border-color: #1890ff;
    background: #1890ff;
  }

  .el-radio__input.is-disabled + span.el-radio__label {
    color: #333;
  }

  .info-list {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;

    .articles-numbers {
      margin-bottom: 5px;

      a {
        font-size: 14px;
        margin-left: 15px;
        color: #1890ff;

        &:hover {
          opacity: 0.7;
        }
      }
    }

    .wn-in-box {
      display: flex;
    }

    .list-box {
      .box-input {
        display: flex;
        margin-right: 30px;
        align-items: center;
        margin-bottom: 5px;
        position: relative;

        .input-select {
          margin-left: 5px;
        }

        p {
          flex-shrink: 0;
          width: 70px;
          font-size: 14px;
          margin: 0px;
        }

        .el-input {
          width: auto;
          flex: 1;
        }

        .el-textarea {
          width: 100%;
          flex: 1;
        }

        .drop-menu {
          position: absolute;
          width: 212px;
          box-shadow: 1px 1px 5px 1px #eee;
          max-height: 500px;
          overflow: auto;
          z-index: 9;
          background: #fff;
          left: 70px;
          top: 35px;
          color: #606266;

          p {
            padding: 10px;
            text-align: center;
            width: 100%;
            color: #606266;
          }

          .menu-close {
            position: sticky;
            top: 0;
            width: 212px;
            text-align: right;
            height: 30px;
            background: #fff;
            line-height: 30px;
            border-bottom: 1px solid #eee;

            .search-top {
              display: flex;
              justify-content: space-between;
              align-items: center;

              span {
                font-size: 14px;
                margin-left: 10px;
                color: #606266;
              }
            }

            a {
              padding-right: 10px;
              font-size: 14px;
            }
          }

          .ma-list {
            .list-t {
              text-align: left;
              cursor: pointer;
              border-bottom: 1px solid #eee;
              font-size: 14px;
              padding-top: 5px;
              padding-bottom: 5px;

              &:hover {
                background-color: #f5f7fa;
              }

              .po-content {
                display: flex;
                align-items: center;
              }

              span {
                display: inline-block;
                margin-left: 10px;
                margin-right: 10px;
              }
            }
          }
        }
      }
    }

    .el-input.is-disabled .el-input__inner {
      color: #333;
    }

    .blue-color .is-disabled .el-input__inner {
      color: #1890ff;
    }
  }

  .purchas-content {
    margin-top: 10px;

    .el-table--border {
      border-left: 1px solid #dfe6ec;
    }

    .el-textarea__inner {
      border: none;
    }

    .el-textarea.is-disabled .el-textarea__inner {
      background: none;
    }

    .el-table__row td:first-child,
    .has-gutter th:first-child {
      border-left: none;
    }

    .clearfix {
      p {
        margin: 0;
        margin-bottom: 8px;
      }
    }

    .el-card__header {
      padding-right: 20px;
    }

    .el-input__inner {
      height: 31px;
      line-height: 0;
      padding: 0 5px;
      color: #606266;
    }

    .el-input__icon {
      line-height: 0;
    }

    .el-table .cell {
      overflow: inherit;
    }

    .select-name {
      display: flex;
      align-items: center;

      .el-input {
        flex: 1;
      }

      span {
        line-height: 20px;
        margin-left: 5px;
        font-size: 14px;
        margin-right: 5px;
      }
    }

    .el-card__body {
      padding-bottom: 10px;
    }

    .table-data {
      .el-table__body-wrapper {
        overflow: auto;

        .cell {
          height: auto !important;
        }
      }

      .el-table .el-table__header-wrapper th,
      .el-table .el-table__fixed-header-wrapper th {
        height: 35px !important;
      }

      .cell {
        padding: 0;
      }

      .el-input--medium .el-input__inner {
        background: none;
        border-color: #fff;
        border-radius: 0;
        padding: 0;
        text-align: center;
      }

      .el-form-item.is-error .el-input__inner,
      .el-form-item.is-error .el-input__inner:focus,
      .el-form-item.is-error .el-textarea__inner,
      .el-form-item.is-error .el-textarea__inner:focus {
        border-color: #ff4949;
      }

      .el-table--enable-row-hover .el-table__body tr:hover > td {
        background: none;
      }

      .el-table--medium th,
      .el-table--medium td {
        padding: 0 !important;
        text-align: center;
      }

      .el-form-item--medium .el-form-item__content {
        line-height: 30px;
      }

      .add-icon {
        margin-top: 5px;
        text-align: center;
      }
    }

    .el-form-item__error {
      padding-top: 0;
      top: 90%;
    }
  }

  .save-btn {
    margin: 20px;

    button {
      width: 200px;
    }
  }

  .el-form-item {
    margin-bottom: 0;
  }

  .button-plan span {
    display: inline-block;

    button {
      margin-left: 10px;
    }
  }

  .invoice-box {
    background-color: #f5f7fa;
    border-color: #dfe4ed;
    width: 100%;
    padding: 0px 15px;
    height: 32px;
    line-height: 27px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    margin-bottom: 3px;
    margin-top: 3px;

    span {
      font-size: 14px;
    }
  }

  .text-right {
    input {
      text-align: right !important;
      padding-right: 10px !important;
    }

    span {
      display: inline-block;
      padding-right: 10px;
      width: 100%;
      text-align: right;
    }
  }

  .select-box {
    position: relative;

    .drop-menu1 {
      position: absolute;
      width: 395px;
      box-shadow: 1px 1px 5px 1px #eee;
      max-height: 300px;
      overflow: auto;
      z-index: 9;
      background: #fff;

      .menu-close {
        position: sticky;
        top: 0;
        width: 395px;
        text-align: right;
        height: 30px;
        background: #fff;
        line-height: 30px;

        .search-top {
          display: flex;
          justify-content: space-between;
          align-items: center;

          span {
            font-size: 14px;
            margin-left: 10px;
          }
        }

        a {
          padding-right: 10px;
        }
      }

      .ma-list {
        margin-bottom: 10px;

        .list-t {
          text-align: left;
          cursor: pointer;
          border-bottom: 1px solid #eee;
          font-size: 14px;

          &:hover {
            background-color: #f5f7fa;
          }

          span {
            display: inline-block;
            margin-left: 10px;
            margin-right: 10px;
          }
        }
      }
    }
  }

  .matrial-box .basicfile-box .cell {
    height: auto !important;
  }

  .el-card__header {
    padding-right: 20px;
  }
}
</style>
